import java.util.Arrays;

class Solution {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int count=0;
        int cur=nums.length-1;
        int left=0;
        int right=cur-1;
        for(;cur>1;cur--){
            right=cur-1;
            left=0;

            while(left<right){

                if(nums[left]+nums[right]>nums[cur]){
                    count+=right-left;
                    right--;


                }else{
                    left++;
                }




            }





        }
        return count;
    }
}